package com.resrun.model;

import com.resrun.vo.request.CACertRequest;
import lombok.Data;

import java.nio.charset.StandardCharsets;
import java.util.Date;

/**
 * 证书记录信息
 *
 * @author hupan
 * @since 2024-01-23
 */
@Data
public class CACert {

    /**
     * 主键ID
     */
    private Long id;

    /**
     * 申请记录ID
     */
    private Long requestId;

    /**
     * 证书别名
     */
    private String alias;

    /**
     * 证书序列号
     */
    private String serial;

    /**
     * 证书格式
     */
    private String format;

    /**
     * 证书密码
     */
    private String password;

    /**
     * 证书编码
     */
    private byte[] encode;

    /**
     * 生效日期
     */
    private Date effectiveDate;

    /**
     * 失效日期
     */
    private Date expirationDate;

    /**
     * 吊销日期
     */
    private Date revokeDate;

    /**
     * 证书状态
     */
    private Byte state;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;


    public static CACert of(CACertRequest request) {
        CACert cert = new CACert();
        cert.setRequestId(request.getRequestId());
        cert.setEncode(request.getEncode());
        cert.setEffectiveDate(request.getEffectiveDate());
        cert.setExpirationDate(request.getExpirationDate());
        cert.setState(request.getState());

        return cert;
    }

}
